package org.lex.ftp.ui.explorer.file;

import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import org.lex.ftp.model.FTPFileView;
import org.lex.ftp.model.LocalFTPFileView;
import org.lex.net.ftp.IFTPFile;


public class FileNameRenderer extends DefaultTableCellRenderer {
	private FTPFileView view = new LocalFTPFileView();

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		IFTPFile file = (IFTPFile) value;
		this.setIcon(view.getIcon(file));
		return super.getTableCellRendererComponent(table, file.getName(), isSelected, hasFocus, row, column);
	}

	public void setBounds(int x, int y, int width, int height) {
		if (getHorizontalAlignment() == 10)
			width = Math.min(width, getPreferredSize().width + 4);
		else
			x -= 4;
		super.setBounds(x, y, width, height);
	}
}
